import 'package:basic_library/basic_library.dart';
import 'package:flutter/material.dart';

/// hero 转场动画
class HeroAnimation extends StatelessWidget {
  final Widget? child;

  const HeroAnimation({Key? key, this.child}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: const Text("hero 转场动画")),
      body: Center(
        child: Column(
          children: [
            GestureDetector(
              onTap: () {
                Navigator.push(
                    context,
                    MaterialPageRoute(
                        builder: (_) => NewPage(child: child),
                        fullscreenDialog: true));
              },
              child: Hero(
                tag: "imgTag",
                child: Container(
                  margin: const EdgeInsets.only(top: 200),
                  color: Colors.red,
                  width: 150,
                  height: 150,
                  alignment: Alignment.center,
                  child: const Text(
                    "跳转",
                    style: StandardTextStyle.big,
                  ),
                ),
              ),
            )
          ],
        ),
      ),
    );
  }
}

class NewPage extends StatelessWidget {
  final Widget? child;

  const NewPage({Key? key, this.child}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Column(
        children: [
          Row(
            children: [
              Expanded(
                child: GestureDetector(
                    onTap: () => Navigator.pop(context),
                    child: Hero(
                        tag: "imgTag",
                        child: Container(color: Colors.red, height: 300))),
              )
            ],
          ),
          const SizedBox(height: 30),
          const Text('阿斯达大所大所多'),
          const SizedBox(height: 30),
          const Text('阿斯达大所大所多'),
          const SizedBox(height: 30),
          const Text('阿斯达大所大所多'),
          const SizedBox(height: 30),
          const Text('阿斯达大所大所多')
        ],
      ),
    );
  }
}
